package com.example.duanjunjie.learn.recycleview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.duanjunjie.learn.R;
import com.example.duanjunjie.learn.utils.LogUtil;

import org.w3c.dom.Text;

/**
 * Created by duanjunjie on 2018/3/14.
 */

public class MyAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private int createCount;
    private int bindCount;

    public MyAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.layout_recycleview,parent,false);
        Log.i("djj","onCreateViewHolder"+createCount++);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((MyViewHolder)holder).textView.setText(position+"");
    }

    @Override
    public int getItemCount() {
        return 20;
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView textView;

        public MyViewHolder(View itemView) {
            super(itemView);
            textView=itemView.findViewById(R.id.textView2);
        }
    }
}
